package com.example.mysongplayer;
//连接后端数据和前端显示的适配器接口，数据和View之间的纽带
//列表的展示需要
// 1.listview 展示列表的view
// 2.适配器 把数据映射到ListView上的中介
// 3.数据 具体的将被映射的字符串，图片，或者基本组件

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class SongAdapter extends ArrayAdapter {
    private final int resourceid;
    public SongAdapter(Context context, int textViewResourceid, List<Song> songs){
        super(context,textViewResourceid,songs);
        resourceid=textViewResourceid;
    }
    @SuppressLint("ResourceType")
    public View getView(int positon , View convertView, ViewGroup parent){
        Song song=(Song)getItem(positon);
        View view = LayoutInflater.from(getContext()).inflate(resourceid,null);
        ImageView songImage=(ImageView)view.findViewById(R.id.song_cover);
        TextView textView=(TextView)view.findViewById(R.id.song_name);
        TextView singer_View=(TextView)view.findViewById(R.id.song_singer);
        songImage.setImageResource(R.raw.music);
        textView.setText(song.getName());
        singer_View.setText(song.getSinger());
        return view;
    }

}
